/*
 * This file is part of algowala.
 *
 * algowala is copyright (c) 2012 Jagannathan Sampath <algowala@jagernot.com>
 *
 * algowala is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * algowala is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with algowala.  If not, see <http://www.gnu.org/licenses/>.
 *
*/
#ifndef __chrono
#define __chrono

#include <ctime>
#include <time.h>

#include <boost/date_time/posix_time/posix_time.hpp>

void find_elapsed (const timespec& start, const timespec& end, timespec& result); // elapsed time in sec:nanosecs between start/end

struct chrono1 { // nanosecond precision clock

  timespec start, now, result;

  double secs; // time in seconds
  double time_scale; // speeds up (> 1) or slows down (0 < scale < 1) or keeps time ( == 1)

  void reset ();
  void tick ();
  void set_time_scale (double s) {if (time_scale > 0) time_scale = s;}

  chrono1 (double _time_scale = 1);
  
  

};

struct chrono { // uses boost
  
  static boost::posix_time::ptime market_open, market_close; // market open/close times
  
  boost::posix_time::ptime start, now; // start time (set at reset), current time
  
  boost::posix_time::time_duration elapsed; // elapsed time from market open
      
  double secs; // elapsed time since start in seconds
    
  double time_scale; // speeds up (> 1) or slows down (0 < scale < 1) or keeps time ( == 1)

  chrono (double _time_scale = 1);
  
  void set_time_scale (double ts) {if (ts > 0) time_scale = ts;}
  void reset ();
  void tick ();
  long get_seed ();
  
  std::string get_wall_clock ();
  std::string get_wall_clock (double s, const boost::posix_time::ptime& startt = market_open);
  
};

#endif
